package scripts.sea;

import api.sea.*;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import util.AssertUtil;
import util.HttpClientUtils;
import util.ResponseData;

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 批量待遇配列表
 */
public class TestBatchStayStuff {
    private String id;
    private String code;
    private String all_id;
    private String all_code;
    Date date = new Date();
    SimpleDateFormat time = new SimpleDateFormat("HH-mm-ss");
    private final String s = time.format(date);
    private static final Logger logger = LoggerFactory.getLogger(TestLogin.class);
    private static final StayPreplanApi stayPreplanApi = new StayPreplanApi();
    private final String number = RandomStringUtils.randomNumeric(8);

    @Test
    public void test_01() throws IOException, URISyntaxException {
        ResponseData responseData = LoginApi.login("admin", "qf123456?");
        String data = responseData.getBody().getJSONObject("data").getString("logistics-token");
        HttpClientUtils.build_header("logistics-token", data);
        HttpClientUtils.build_header("Content-Type", "application/json");
    }

    @Test(invocationCount = 10)
    public void test_02() throws IOException, URISyntaxException {
        JSONArray data = new JSONArray();
        Map<String, String> map_data = new HashMap<>();
        map_data.put("cartons", "1");
        map_data.put("length", "1");
        map_data.put("width", "1");
        map_data.put("mark", "Tokyo  Hot");
        map_data.put("weight", "1");
        data.add(map_data);
        String date_time = "QFHY-" + s;
        ResponseData responseData = DelegationApi.delegation("TCY179310074272899092", "COOLPAI", "" + date_time,
                0, "", data, "2021-03-22",
                "LIANYUNGANG", "CHICAGO", "pingming", "2021-04-06", "3", "" + date_time,
                "1", "LWL" + s,
                "100", "1", "0", "", "", "", "",
                1, 1, 1,
                "", "", "US", "", "", "", "", "Tokyo  Hot", "",
                "", "" + date_time,
                "6", "1", "0", 0, "王晓亮", "5409d88922bf4d5187f4",
                "7cd6188ea979499e892e", "黄德挺",
                "7cd6188ea979499e892e", "黄德挺", "创实",
                "CU163032594897092663", 2);
        this.id = responseData.getBody().getJSONObject("data").getString("id");
        this.code = responseData.getBody().getJSONObject("data").getString("entrustmentCode");
        logger.info("id={}", id);
        all_id = id + ',' + all_id;
        all_code = code + "," + all_code;
    }
    @Test
    public void test_03() throws IOException, URISyntaxException {
        String[] strings = all_id.split(",null");
        String[] strings1 = all_code.split(",null");
        StringBuilder stringBuffer=new StringBuilder();
        StringBuilder stringBuilder=new StringBuilder();
        for(String s:strings){
            stringBuffer.append(s);
        }
        for(String s1:strings1){
            stringBuilder.append(s1);
        }
        String str_id=stringBuffer.toString();
        String str_code=stringBuilder.toString();
        ResponseData responseData=stayPreplanApi.stay_preplan(str_code,str_id,number,
                10,10,10,"LIANYUNGANG","CHICAGO","2","4",
                "DDD","2021-04-25","2021-04-25",1);
        AssertUtil.assertCommon(responseData,0,"成功");
        logger.info("number={}",number);

    }
}
